#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Coord {
    pub x: i32,
    pub y: i32,
}

impl Coord {
    pub fn new(x: i32, y: i32) -> Self {
        Self { x, y }
    }

    pub fn xy(&self) -> (i32, i32) {
        (self.x, self.y)
    }

    pub fn adjacent_coords(&self) -> [Coord; 4] {
        let (x, y) = self.xy();
        [
            Coord::new(x - 1, y),
            Coord::new(x + 1, y),
            Coord::new(x, y - 1),
            Coord::new(x, y + 1),
        ]
    }

    pub fn manhattan_distance(&self, other: &Self) -> i32 {
        (self.x - other.x).abs() + (self.y - other.y).abs()
    }
}
